package com.collectplus.express.passport;

import android.os.Message;
import android.widget.ListView;
import android.widget.TextView;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppHttp;
import com.collectplus.express.logic.AppResult;
import com.collectplus.express.logic.JSON;
import com.collectplus.express.logic.MsgID;
import com.collectplus.express.model.ParcelDetailBean;
import com.collectplus.express.parcel.ParcelRouteAdapter;

import droid.frame.utils.sqlite.DateUtils;

/**
 * 裹儿令牌、运单信息
 * 
 * @author coffee<br>
 *         2017-1-6下午4:33:41
 */
public class PassportExpressActivity extends BaseActivity2 {

	private ListView mListView;

	@Override
	protected void findViewById() {
		setContentView(R.layout.passport_express);
		super.findViewById();
		getAppTitle().setCommonTitle("物流信息");
		//
		ParcelDetailBean item = (ParcelDetailBean) getIntent().getSerializableExtra("item");
		showLoadingDialog(null);
		AppHttp.getInstance().orderDetail(item.getOrderId());

		mListView = (ListView) findViewById(R.id.listview);
		TextView senderName = (TextView) findViewById(R.id.passport_sender_name);
		TextView senderCity = (TextView) findViewById(R.id.passport_sender_city);
		TextView receiverName = (TextView) findViewById(R.id.passport_receiver_name);
		TextView receiverCity = (TextView) findViewById(R.id.passport_receiver_city);
		TextView orderTime = (TextView) findViewById(R.id.passport_order_time);
		TextView express = (TextView) findViewById(R.id.passport_express);

		senderName.setText(item.getSendName());
		senderCity.setText("北京");
		receiverName.setText(item.getReceiverName());
		receiverCity.setText("");
		orderTime.setText("下单时间: " + DateUtils.format(item.getOrderTime()));
		express.setText(item.getExpressCompanyName() + " " + item.getExpressNumber());
	}

	@Override
	public boolean handleMessage(Message msg) {
		switch (msg.what) {
		case MsgID.order_detail:
			cancelLoadingDialog();
			final AppResult<ParcelDetailBean> result = JSON.parser(msg.obj, ParcelDetailBean.class);
			if (result.isSuccess()) {
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						ParcelDetailBean item = result.getResult();
						ParcelRouteAdapter adapter = new ParcelRouteAdapter(item.getRouteList(), getContext());
						mListView.setAdapter(adapter);
					}
				});
			} else {
				showToast(result.getMessage());
			}
			return true;
		default:
			return super.handleMessage(msg);
		}
	}
}